<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增用户</title>
    <link th:href="@{/img/Bandit.ico}" rel="icon">
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet">
    <link th:href="@{/editor.md-master/css/editormd.css}" rel="stylesheet" >
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div th:replace="~{commons/common::BackHeader}"></div>
    <div class="layui-body">
        <fieldset class="layui-elem-quote">新增用户</fieldset>
        <form class="layui-form" id="userAdd" style="width: 1680px">
            <!--标题-->
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="username" id="username" placeholder="输入用户名" autocomplete="false" required lay-verify= "required">

                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="password" id="password" placeholder="输入密码" autocomplete="false" required lay-verify= "required">

                </div>
            </div>
            <!--类型-->
            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-block">
                    <select name="permission" lay-filter="type" id="typeSelect">
                        <option th:each="permission:${permissionList}" th:value="${permission}" th:text="${permission}"></option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit id="save_btn">点击添加</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/editor.md-master/editormd.js}"></script>
<script type="text/javascript">
    var prefix = "/back/user";
    $(function() {
        $('#userAdd').on('submit', function (e){
            let layer;
            layui.use(['layer'],function(){
                layer = layui.layer;
                layer.load(1);
            })
            e.preventDefault();
            let Data = $(this).serializeArray();
            console.log(Data);
            $.ajax({
                type: 'POST',
                url: prefix + '/addConfirm',
                data: {
                    "username":Data[0].value,
                    "password":Data[1].value,
                    "permission":Data[2].value,
                },
                dataType: 'json',
                success: function (res) {
                    console.log(res.msg);
                    parent.layer.closeAll();
                    layer.msg('添加成功！');
                    setTimeout(function(){
                        parent.layer.closeAll();
                        window.location.href = prefix + '/list';
                    },2000)
                },
                error: function () {
                    console.log("错误");
                }
            })
        });

    });
</script>
<script th:replace="~{commons/common::Editor_Img}"></script>
</body>
</html>